﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using Thaire.Investment.Domains.Transaction;

namespace Thaire.Investment.Repository
{
    public class DepositInterestRepo : BaseRepository<DepositInterest, int>
    {
        public DepositInterestRepo(ISession session)
            : base(session)
        {
        }

        public List<DepositInterest> GetByDepositHeaderID(int headerId)
        {
            return new List<DepositInterest>(_session.QueryOver<DepositInterest>()
                 .Where(x => x.DepositHeaderID == headerId)
                 .OrderBy(x => x.InterestApplyDate).Desc.List());
        }

        public DepositInterest GetMaxApplyDate(DateTime applyDate)
        {
            return  new List<DepositInterest>(_session.QueryOver<DepositInterest>()
                 .Where(x => x.InterestApplyDate <= applyDate)
                 .OrderBy(x => x.InterestApplyDate).Desc.List()).FirstOrDefault();
        }
    }
}
